package net.lab1024.sa.admin.module.business.category.domain.entity;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.LinkedHashMap;
import java.util.Map;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class RetroResult {
    private String error;  // 错误信息（如果有）
    private final Map<String, SynthesisPath> paths = new LinkedHashMap<>();

    // 处理动态键值对
    @JsonAnySetter
    public void addPath(String key, Object value) {
        if (value instanceof Map) {
            ObjectMapper mapper = new ObjectMapper();
            SynthesisPath path = mapper.convertValue(value, SynthesisPath.class);
            paths.put(key, path);
        }
    }

    @Data
    @NoArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class SynthesisPath {
        @Schema(description = "逆合成路径评分，数值越高表示路径越优", example = "0.85")
        @JsonProperty("Score")
        private Double score;

        @Schema(description = "逆合成反应模板的SMARTS表达式",
                example = "[C:1]=[O;H0;D2:2]>>[C:1]-[OH;D1:2]")
        @JsonProperty("Template")
        private String template;

        @Schema(description = "逆合成模板的唯一标识ID", example = "123")
        @JsonProperty("Template_id")
        private Integer templateId;

        @Schema(description = "反应条件（如温度、催化剂等），可能为字符串或复杂对象",
                example = "{\"temperature\": \"25°C\", \"catalyst\": \"Pd(OAc)2\"}")
        @JsonProperty("Condition")
        private Object condition;
    }
}